package com.holly.unit.deform.api.factory;

import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.holly.unit.deform.api.pojo.tool.DesformWidget;

/**
 * 类描述: 省市区换模式
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/4/14 15:04
 */
public class AreaLinkageConverter extends ForeseeConvert{

    ProvinceCityArea provinceCityArea;

    public AreaLinkageConverter(DesformWidget widget) {
        this.model = widget.getModel();
        this.provinceCityArea = SpringUtil.getBean(ProvinceCityArea.class);
    }

    @Override
    public String converterToVal(String txt) {
        if (StrUtil.isEmpty(txt)) {
            return null;
        }
        return provinceCityArea.getCode(txt);
    }

    @Override
    public String converterToTxt(String val) {
        if (StrUtil.isEmpty(val)) {
            return null;
        }
        return provinceCityArea.getText(val);
    }


}
